﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;

namespace Gmantis.Controls.DataGrid
{
    public class DataGridColumnHeaderTypeConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return (Type.GetTypeCode(sourceType) == TypeCode.String);
        }

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = ((string)value).Trim();
            if (!str.StartsWith("[") || !str.EndsWith("]"))
            {
                return value;
            }
            string[] strArray = str.Substring(1, str.Length - 2).Split(new char[] { ',' });
            List<string> list = new List<string>();
            foreach (string str3 in strArray)
            {
                list.Add(str3.Trim());
            }
            return list;
        }
    }
}
